<style>
    .layui-form-item .layui-inline {
        margin-top: 10px;
    }
</style>
<div class="layui-fluid" id="Ship-create">
    <div class="layui-card">
        <div class="layui-form" lay-filter="LAY-list-form">
            <div id="view"></div>
        </div>
    </div>
</div>
<script id="page1" type="text/html">
    <input type="hidden" name="id" value="{{layui.router().search.id||''}}">
    <div class="layui-card-header">入库单资料</div>
    <div class="layui-card-body">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label layui-label-jy">入库批次号:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.result.code||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label layui-label-jy">业务单号:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.result.bs_code||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label layui-label-jy">发货公司:</label>
                <div class="layui-input-inline  layui-jy-width200">
                    <input type="hidden" value="10002" name="company_id_out" class="layui-input ">
                    <span class="layui-input layui-input-none">{{d.info.company[10002]}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label layui-label-jy">发货仓库:</label>
                <div class="layui-input-inline">
                    <input type="hidden" value="30001" name="warehouse_id_out" class="layui-input ">
                    <span class="layui-input layui-input-none">{{d.info.warehouse[30001]||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label layui-label-jy">收货仓库:</label>
                <div class="layui-input-inline">
                     <span class="layui-input layui-input-none">{{d.result.receipt_warehouse_str||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label layui-label-jy">入库类型:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.result.type_str||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label layui-label-jy">入库状态:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.result.status_str||''}}</span>
                </div>
            </div>
            {{# if(d.result.type==20){ }}
            <div class="layui-inline">
                <label class="layui-form-label layui-label-jy">确定人:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.result.user||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label layui-label-jy">确定时间:</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.result.date||''}}</span>
                </div>
            </div>
            {{# } }}
        </div>
    </div>

    <div class="layui-card-header">商品信息</div>
    <div class="layui-card-body">
        <div class="layui-item">
            <button class="export1 layui-btn">导出</button>
            {{# if(d.result.status==10&&d.result.bs_code.indexOf("FY") == -1){  }}
            <button class="uploadPage layui-btn">上传</button>
            {{# } }}
        </div>
        <table id="LAY-list" lay-filter="LAY-list"></table>
    </div>

    <div class="layui-card-body layui-jy-center">
        <a lay-href="Warehousecountry/input" class="layui-btn">返回</a>
        {{# if(d.result.status==10) { }}
        <input type="button" lay-submit lay-filter="LAY-submit-1" value="确定入库" class="layui-btn LAY-submit1">
        {{#} }}
    </div>

</script>
<!-- 行内工具 -->
<script type="text/html" id="LAY-list-toolbar">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="del" href="javascript:;">删除</a>
</script>
<script>
    layui.use(['admin', 'form', 'toolJ', 'laytpl', 'laydate', 'upload', 'table'], function () {
        var $ = layui.$
            , form = layui.form
            , laytpl = layui.laytpl
            , setter = layui.setter
            , laydate = layui.laydate
            , table = layui.table
            , toolJ = layui.toolJ;
        var id = layui.router().search.id;
            //监听上传按钮
        $('#Ship-create').off('click.uploadPage').on('click.uploadPage', '.uploadPage', function () {
                upload();
        })
        //导出
        $("body").off('click.export1').on('click.export1', '.export1', function () {
            $(".layui-table-tool .layui-inline[lay-event='LAYTABLE_EXPORT']").click();
            $(".layui-table-tool li[data-type='csv']").click();
        })
        //详情
        function tableView1(data) {
            table.render({
                elem: '#LAY-list'
                , data: data
                , toolbar: true
                , defaultToolbar: ['exports', 'filter', 'print']
                , cellMinWidth: 80
                , cols: [[
                    {field: 'case_number', title: '箱唛号'}
                    ,{field: 'shop_name', title: '店铺'}
                    , {field: 'sku', title: 'sku'}
                    , {field: 'sku_name', title: '采购名称'}
                    , {field: 'quantity', title: '入库数量',}
                    , {field: 'price', title: '单价'}
                    , {field: 'remark', title: '备注', edit: 'text'}
                ]]
                , page: false
                , limit: 100000
                ,text:{none: '暂无相关数据!' }
            });
        }
        //详情
        function tableView2(data) {
            table.render({
                elem: '#LAY-list'
                , data: data
                , toolbar: true
                , defaultToolbar: ['exports', 'filter', 'print']
                , cellMinWidth: 80
                , cols: [[
                    {field: 'case_number', title: '箱唛号'}
                    , {field: 'sku', title: 'sku'}
                    , {field: 'sku_name', title: '采购名称'}
                    , {field: 'quantity', title: '入库数量', edit: 'text'}
                    , {field: 'price', title: '单价'}
                    , {field: 'remark', title: '备注', edit: 'text'}
                ]]
                , page: false
                , limit: 100000
                ,text:{none: '暂无相关数据!' }
            });
        }

        function upload() {
            layer.open({
                title: '上传',
                type: 1,
                skin: 'layui-layer-rim', //加上边框
                area: ['420px', '240px'], //宽高
                content: '<div style="width: 280px; margin: 0 auto; margin-top: 64px;">' +
                    '<button type="button" style="margin-right: 20px" class="layui-btn" id="layUploadBtn"><i class="layui-icon"></i>上传文件</button>' +
                    '<a href="/attachment/importcvs/warehousecountry.csv" class="layui-btn layui-btn-primary"><i class="layui-icon"></i>下载模板</a>' +
                    '</div>'
            });
            //上传文件 指定允许上传的文件类型
            layui.upload.render({
                elem: '#layUploadBtn'
                , data: {"id": id}
                , url: '/index/Warehousecountry/upload'
                , accept: 'file' //普通文件
                , exts: 'csv' //只允许上传csv文件
                , done: function (res) {
                    layer.closeAll();
                    if (res.code == 1) {
                        if (res.msg) {
                            layer.msg(res.msg);
                        }
                        tableView2(res.data);
                    } else {
                        layer.alert(res.msg);
                    }
                }
                , before: function () {
                    layer.alert('执行中,请勿做其他操作!');
                    layer.load(1, {
                        shade: [0.5, '#fff']
                    });
                }
                , error: function () {
                    layer.closeAll();
                    layer.alert('失败,请稍后再试!');
                }
            });
        }

        function viewHtml(data) {
            var getTpl = page1.innerHTML
                , view = $('#view');
            laytpl(getTpl).render(data, function (html) {
                view.html(html);
            });
            if(data.result.bs_code.indexOf("FY") == -1){
                tableView2(data.detail);
            }else{
                tableView1(data.detail);
            }
            table.render(null, 'LAY-list');
            form.render(null, 'LAY-list-form');

            //监听提交
            form.on('submit(LAY-submit-1)', function (data) {
                    data.field.list = JSON.stringify(table.cache['LAY-list']);
                    toolJ.ajax({"data": data.field,"url":"/index/Warehousecountry/inputEdit"});
            })
        }
        var info = {};
        info.shop = layui.data(setter.tableName).shop;
        info.warehouse = layui.data(setter.tableName).warehouse;
        info.company = layui.data(setter.tableName).company;
        info.warehouseCountry = layui.data(setter.tableName).warehouseCountry;
        if (id) {
            toolJ.ajax({"data": {"id": id}, "type": "get"},
                function (data) {
                    info.myCompany=data.data.myCompany;
                    info.lsCompany=data.data.lsCompany;
                    info.countryWarehouse=data.data.countryWarehouse;
                    viewHtml({"info": info, "result": data.data.result, "type": 1, "detail": data.data.detail});
                }
            );
        }


    })
</script>